package com.esri.core.internal.tasks.c;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.f;
import com.esri.core.internal.util.d;
import com.esri.core.io.EsriServiceException;
import com.github.mikephil.charting.utils.Utils;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.util.MinimalPrettyPrinter;

/* loaded from: classes.dex */
public class b extends f {
    private static final String A = "returnZ";
    private static final String B = "returnM";
    public static final int a = 0;
    public static final int b = 1;
    public static final int c = 2;
    private static final long serialVersionUID = 1;
    private static final String t = "tolerance";
    private static final String u = "mapExtent";
    private static final String v = "sr";
    private static final String w = "geometry";
    private static final String x = "geometryType";
    private static final String y = "returnGeometry";
    private static final String z = "layerDefs";
    String d;
    Geometry e;
    Envelope f;
    SpatialReference g;
    int h;
    int[] i;
    int j;
    int k;
    int l;
    int m;
    boolean n;
    double o;
    boolean p;
    boolean q;
    String r;
    HashMap<String, String> s;

    public b() {
        this.d = "json";
        this.h = 0;
        this.j = 0;
        this.k = 0;
        this.l = 0;
        this.m = 5;
        this.n = true;
        this.o = Utils.DOUBLE_EPSILON;
        this.p = false;
        this.q = false;
        this.s = new HashMap<>();
    }

    public b(Geometry geometry, Envelope envelope, SpatialReference spatialReference, int[] iArr, int i, int i2, int i3) {
        this.d = "json";
        this.h = 0;
        this.j = 0;
        this.k = 0;
        this.l = 0;
        this.m = 5;
        this.n = true;
        this.o = Utils.DOUBLE_EPSILON;
        this.p = false;
        this.q = false;
        this.s = new HashMap<>();
        this.e = geometry;
        this.f = envelope;
        this.i = iArr;
        this.j = i;
        this.k = i2;
        this.l = i3;
        this.g = spatialReference;
    }

    public Geometry a() {
        return this.e;
    }

    public Envelope b() {
        return this.f;
    }

    public int[] c() {
        return this.i;
    }

    public int d() {
        return this.j;
    }

    public int e() {
        return this.k;
    }

    public int f() {
        return this.l;
    }

    public int g() {
        return this.h;
    }

    public int h() {
        return this.m;
    }

    public boolean i() {
        return this.n;
    }

    public HashMap<String, String> j() {
        return this.s;
    }

    public void a(HashMap<String, String> hashMap) {
        this.s = hashMap;
    }

    public void a(boolean z2) {
        this.n = z2;
    }

    public void a(int i) {
        this.h = i;
    }

    public void b(int i) {
        this.m = i;
    }

    public void a(Geometry geometry) {
        this.e = geometry;
    }

    public void a(Envelope envelope) {
        this.f = envelope;
    }

    public void a(int[] iArr) {
        this.i = iArr;
    }

    public void c(int i) {
        this.j = i;
    }

    public void d(int i) {
        this.k = i;
    }

    public void e(int i) {
        this.l = i;
    }

    @Override // com.esri.core.internal.tasks.f
    public boolean validate() {
        if (a() == null) {
            throw new EsriServiceException("A geometry must be provided to the identify task.");
        }
        if (b() == null) {
            throw new EsriServiceException("An extent must be provided to the identify task.");
        }
        if (e() <= 0 || d() <= 0 || f() <= 0) {
            throw new EsriServiceException("Height, width and Dot-per-inch (DPI) values must be greater than 0.");
        }
        return true;
    }

    public SpatialReference k() {
        return this.g;
    }

    public double l() {
        return this.o;
    }

    public void a(double d) {
        this.o = d;
    }

    public void a(SpatialReference spatialReference) {
        this.g = spatialReference;
    }

    public boolean m() {
        return this.p;
    }

    public void b(boolean z2) {
        this.p = z2;
    }

    public boolean n() {
        return this.q;
    }

    public void c(boolean z2) {
        this.q = z2;
    }

    public String o() {
        return this.r;
    }

    public void a(String str) {
        this.r = str;
    }

    @Override // com.esri.core.internal.tasks.f
    public Map<String, String> generateRequestParams() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("f", this.d);
        int g = g();
        String str = "all";
        if (g != 0) {
            if (g == 1) {
                str = "visible";
            } else if (g == 2) {
                str = "top";
            }
        }
        int[] c2 = c();
        if (c2 != null && c2.length > 0) {
            String replaceAll = Arrays.toString(c2).replaceAll(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, "");
            linkedHashMap.put("layers", String.format("%1$s:%2$s", str, replaceAll.substring(1, replaceAll.length() - 1)));
        } else {
            linkedHashMap.put("layers", str);
        }
        linkedHashMap.put(x, d.a(this.e.getType()));
        try {
            linkedHashMap.put(w, GeometryEngine.geometryToJson(this.g, this.e));
            linkedHashMap.put(u, GeometryEngine.geometryToJson(this.g, b()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        SpatialReference spatialReference = this.g;
        if (spatialReference != null && spatialReference.getID() > 0) {
            linkedHashMap.put(v, Integer.toString(this.g.getID()));
        }
        linkedHashMap.put(t, Integer.toString(h()));
        linkedHashMap.put("imageDisplay", String.format("%1$d,%2$d,%3$d", Integer.valueOf(d()), Integer.valueOf(e()), Integer.valueOf(f())));
        HashMap<String, String> hashMap = this.s;
        if (hashMap != null && hashMap.size() > 0) {
            StringWriter stringWriter = new StringWriter();
            try {
                JsonGenerator a2 = d.a(stringWriter);
                a2.writeStartObject();
                for (String str2 : this.s.keySet()) {
                    a2.writeStringField(str2, this.s.get(str2));
                }
                a2.writeEndObject();
                a2.close();
                linkedHashMap.put(z, stringWriter.toString());
            } catch (JsonGenerationException e2) {
                e2.printStackTrace();
            } catch (IOException e3) {
                e3.printStackTrace();
            }
        }
        linkedHashMap.put(y, Boolean.toString(i()));
        double d = this.o;
        if (d > Utils.DOUBLE_EPSILON) {
            linkedHashMap.put("maxAllowableOffset", Double.toString(d));
        }
        linkedHashMap.put(y, Boolean.toString(this.n));
        linkedHashMap.put(A, Boolean.toString(this.p));
        linkedHashMap.put(B, Boolean.toString(this.q));
        String str3 = this.r;
        if (str3 != null && str3.length() > 0) {
            linkedHashMap.put("gdbVersion", this.r);
        }
        return linkedHashMap;
    }
}
